package com.jingxing.provider;

import org.apache.commons.lang3.StringUtils;

/**
 * @author han
 * @title: RewardReceiveMapperProvider
 * @date 2021/9/15 10:12
 */
public class RewardReceiveMapperProvider {

    public String getRewardReceives(String playerName, String prizeName){
        StringBuilder sql = new StringBuilder();
        sql.append("SELECT\n" +
                "r.id,\n" +
                "r.player_id AS playerId,\n" +
                "r.prize_id AS prizeId,\n" +
                "p.`name` AS playerName,\n" +
                "s.prize_name AS prizeName,\n" +
                "r.receive_sfrequency AS receiveSfrequency,\n" +
                "r.create_time AS createTime,\n" +
                "(SELECT user_info.`name` FROM user_info WHERE id = r.create_by) AS createBy,\n" +
                "r.update_time AS updateTime,\n" +
                "(SELECT user_info.`name` FROM user_info WHERE id = r.update_by) AS updateBy ");
        sql.append("FROM\n" +
                "reward_receive AS r\n" +
                "LEFT JOIN player_user_info AS p ON r.player_id = p.id\n" +
                "LEFT JOIN sign_up_reward AS s ON r.prize_id = s.id ");
        sql.append("WHERE\n" +
                "r.del = 0 AND\n" +
                "p.del = 0 AND\n" +
                "s.del = 0 ");
        if (StringUtils.isNotBlank(playerName)) {
            sql.append("AND p.`name` = '" + playerName + "' ");
        }
        if (StringUtils.isNotBlank(prizeName)) {
            sql.append("AND s.prize_name = '" + prizeName + "' ");
        }
        return sql.toString();
    }
}
